package implementations.dm_kernel.user;

import implementations.dm_kernel.ConnectorImpl;
import implementations.dm_kernel.MessageCommonsImpl;
import implementations.dm_kernel.MessageControlImpl;
import implementations.dm_kernel.MessageGlobalVarImpl;
import implementations.dm_kernel.MessageRegisterImpl;
import implementations.dm_kernel.MessageTaskImpl;
import interfaces.kernel.JCL_connector;
import interfaces.kernel.JCL_facade;
import interfaces.kernel.JCL_message_commons;
import interfaces.kernel.JCL_message_control;
import interfaces.kernel.JCL_message_global_var;
import interfaces.kernel.JCL_message_register;
import interfaces.kernel.JCL_message_result;
import interfaces.kernel.JCL_result;
import interfaces.kernel.JCL_task;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

import commom.JCL_resultImpl;
import commom.JCL_taskImpl;

/*
 * MESSAGES
 * 
 *  1 public boolean register(File[] f, String classToBeExecuted) {
    2 public boolean unRegister(String nickName) {
    3 public void executeSimple(String objectNickname, Object... args) {
    4 public String execute(String objectNickname, Object... args) {
	5 public String execute(String className, String methodName, Object... args) {
	6 public JCL_result getResultBlocking(String ID) {
	7 public JCL_result getResultUnblocking(String ID) {
	8 public JCL_result removeResult(String ID) {
	9 public Object instantiateGlobalVar(String varName, Class<?> varType,
	10 public boolean instantiateGlobalVar(String varName, Object instance) {
	11 public boolean destroyGlobalVar(String varName) {
	12 public boolean setValue(String varName, Object value) {
	13 public boolean setValueUnlocking(String varName, Object value) {
	14 public JCL_result getValue(String varName) {
	15 public JCL_result getValueLocking(String varName) {
	16 public void destroy() {
	17 public boolean containsGlobalVar(String ninckName){
	18 public boolean containsTask(String ninckName){
	
	METHOD DEPRECATED in JCL distributed version: public boolean register(Class<?> object, String nickName) {
	

 */

public class JCL_FacadeImpl implements JCL_facade {
				
	private Map<String, File[]> jars; 
	private Map<String, String[]> serviceLocation;
	private String serverAdd;
	private int serverPort;
	
		
	protected JCL_FacadeImpl(){
		try{
						
			jars = new TreeMap<String, File[]>();
			serviceLocation = new TreeMap<String, String[]>();
			// Read properties file.
			Properties properties = new Properties();
			try {
			    properties.load(new FileInputStream("../jcl_conf/config.properties"));
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			serverAdd = properties.getProperty("serverMainAdd");
			serverPort = Integer.parseInt(properties.getProperty("serverMainPort"));
			
			System.out.println("client JCL is OK");
			
			
		}catch ( Exception e ){
			System.err.println("JCL facade constructor error");
			
		}
		
	}	
		
	@Override
	public boolean register(File[] f, String classToBeExecuted) {
		try{
						
				//get a JCL host from server
				JCL_message_control mc = new MessageControlImpl();
				
				mc.setRegisterData(classToBeExecuted);
				//calling register service to a specific user
				//the register service is for registering jar files
				mc.setType(1);
				JCL_connector controlConnector = new ConnectorImpl();
				controlConnector.connect(serverAdd, serverPort);
				JCL_message_control mr = controlConnector.sendReceive(mc);
				controlConnector.disconnect();
				if(mr.getRegisterData().length==2){
					String host = mr.getRegisterData()[0];
					String port = mr.getRegisterData()[1];
					JCL_connector taskConnector = new ConnectorImpl();
					//connect to a host
					taskConnector.connect(host, Integer.parseInt(port));
					
					JCL_message_register msg = new MessageRegisterImpl();
					msg.setJars(f);
					msg.setJarsNames(f);
					msg.setClassName(classToBeExecuted);
					//type 1 for registering
					msg.setType(1);
					
					JCL_result result = taskConnector.sendReceive(msg).getResult();
					boolean flag=false;
					if (result.getCorrectResult()!=null)
						flag= ((Boolean)result.getCorrectResult()).booleanValue();
					
					taskConnector.disconnect();
					
					if(flag==true && !jars.containsKey(classToBeExecuted))
						jars.put(classToBeExecuted, f);
					
					return flag;
					
				}else return false;							
			
		}catch(Exception e){
			
			System.err.println("problem in JCL facade register(File f, String classToBeExecuted)");
			e.printStackTrace();
			return false;
		}
	}
	

	@Override
	@Deprecated
	public boolean register(Class<?> object, String nickName) {
		
		try{
				
			System.err.println("cannot use this method with JCL distributed");
			
			return false;
		}catch (Exception e){
			
			System.err.println("cannot use this method with JCL distributed");
			
			return false;
		}
	}
	
	@Override
	public boolean unRegister(String nickName) {
		try{
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(nickName);
			//calling unregister service to a specific user
			//the unregister service is for unregistering jar files
			mc.setType(2);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length>=2){
				
				for(int i=0; i<mr.getRegisterData().length; i+=2){
					String host = mr.getRegisterData()[i];
					String port = mr.getRegisterData()[i+1];
					JCL_connector taskConnector = new ConnectorImpl();
					taskConnector.connect(host, Integer.parseInt(port));
					JCL_message_commons msg = new MessageCommonsImpl();
					msg.setType(2);
					msg.setRegisterData(nickName);
					JCL_message_result msgR = taskConnector.sendReceive(msg);
					if(msgR.getResult().getCorrectResult()!=null)
						System.err.println("Unregistered " + nickName + " " + msgR.getResult().getCorrectResult().toString());
					else msgR.getResult().getErrorResult().printStackTrace();
					taskConnector.disconnect();
				}
				
				jars.remove(nickName);
				
				return true;
			}else return false;			
		}catch (Exception e){
			System.err.println("JCL problem in unregister method");
			e.printStackTrace();
			
			return false;
		}
			
	}

	
	@Override
	public String execute(String objectNickname, Object... args) {
				
		try{
			if(jars.containsKey(objectNickname)){
				JCL_task t = new JCL_taskImpl(null, objectNickname, null, args);
				t.setTaskTime(System.nanoTime());
				MessageTaskImpl msgTask = new MessageTaskImpl();
				msgTask.setTask(t);
				//execute 
				msgTask.setType(4);
				
				//we must verify if it is registered in the host
				JCL_message_control containsTask = new MessageControlImpl();
				containsTask.setType(18);
				containsTask.setRegisterData(objectNickname);		
				
				JCL_message_control mc = new MessageControlImpl();				
				mc.setRegisterData(objectNickname);
				//calling service location to a specific task
				mc.setType(4);
				JCL_connector controlConnector = new ConnectorImpl();
				controlConnector.connect(serverAdd, serverPort);
				JCL_message_control mr = controlConnector.sendReceive(mc);
				controlConnector.disconnect();
				if(mr.getRegisterData().length==2){
					String host = mr.getRegisterData()[0];
					String port = mr.getRegisterData()[1];
					String[] hostPort = {host, port};
									
					JCL_connector containsConnector = new ConnectorImpl();
					containsConnector.connect(host, Integer.parseInt(port));
					JCL_message_control msgContains = containsConnector.sendReceive(containsTask);
					containsConnector.disconnect();
					
					if(msgContains.getRegisterData()[0].equals("false")){
						//we must register before submit a task
						MessageRegisterImpl msg = new MessageRegisterImpl();
						msg.setJars(jars.get(objectNickname));
						msg.setJarsNames(jars.get(objectNickname));
						msg.setClassName(objectNickname);
						//type 1 for registering
						msg.setType(1);
						
						JCL_connector taskConnector = new ConnectorImpl();
						taskConnector.connect(host, Integer.parseInt(port));
						JCL_result result = taskConnector.sendReceive(msg).getResult();
						taskConnector.disconnect();
						boolean flag=false;
						if (result.getCorrectResult()!=null){
							flag= ((Boolean)result.getCorrectResult()).booleanValue();
							if (flag == false) {
								System.err.println("cannot register on host " + hostPort);
								return null;
							}
						}						
					}
					
					JCL_connector taskConnector = new ConnectorImpl();
					taskConnector.connect(host, Integer.parseInt(port));
					JCL_message_result msgResult = taskConnector.sendReceive(msgTask);	
					String ticket = msgResult.getResult().getCorrectResult().toString();
					serviceLocation.put(ticket, hostPort);
					taskConnector.disconnect();
					
					return ticket;
				}else				
					return null;
			}else return null;
			
			
		}catch (Exception e){
			System.err.println("JCL facade problem in execute(String className, Object... args)");
			
			return null;
		}		
	}

	@Override
	public String execute(String objectNickname, String methodName, Object... args) {
				
		try{
			if(jars.containsKey(objectNickname)){
				JCL_task t = new JCL_taskImpl(null, objectNickname, methodName, args);
				t.setTaskTime(System.nanoTime());
				MessageTaskImpl msgTask = new MessageTaskImpl();
				msgTask.setTask(t);
				//execute 
				msgTask.setType(5);
				
				//we must verify if it is registered in the host
				JCL_message_control containsTask = new MessageControlImpl();
				containsTask.setType(18);
				containsTask.setRegisterData(objectNickname);		
				
				JCL_message_control mc = new MessageControlImpl();				
				mc.setRegisterData(objectNickname);
				//calling service location to a specific task
				mc.setType(5);
				JCL_connector controlConnector = new ConnectorImpl();
				controlConnector.connect(serverAdd, serverPort);
				JCL_message_control mr = controlConnector.sendReceive(mc);
				controlConnector.disconnect();
				if(mr.getRegisterData().length==2){
					String host = mr.getRegisterData()[0];
					String port = mr.getRegisterData()[1];
					String[] hostPort = {host, port};
									
					JCL_connector containsConnector = new ConnectorImpl();
					containsConnector.connect(host, Integer.parseInt(port));
					JCL_message_control msgContains = containsConnector.sendReceive(containsTask);
					containsConnector.disconnect();
					
					if(msgContains.getRegisterData()[0].equals("false")){
						//we must register before submit a task
						MessageRegisterImpl msg = new MessageRegisterImpl();
						msg.setJars(jars.get(objectNickname));
						msg.setJarsNames(jars.get(objectNickname));
						msg.setClassName(objectNickname);
						//type 1 for registering
						msg.setType(1);
						
						JCL_connector taskConnector = new ConnectorImpl();
						taskConnector.connect(host, Integer.parseInt(port));
						JCL_result result = taskConnector.sendReceive(msg).getResult();
						taskConnector.disconnect();
						boolean flag=false;
						if (result.getCorrectResult()!=null){
							flag= ((Boolean)result.getCorrectResult()).booleanValue();
							if (flag == false) {
								System.err.println("cannot register on host " + hostPort);
								return null;
							}
						}						
					}
					
					JCL_connector taskConnector = new ConnectorImpl();
					taskConnector.connect(host, Integer.parseInt(port));
					JCL_message_result msgResult = taskConnector.sendReceive(msgTask);	
					String ticket = msgResult.getResult().getCorrectResult().toString();
					serviceLocation.put(ticket, hostPort);
					taskConnector.disconnect();
					
					return ticket;
				}else				
					return null;
			}else return null;
			
			
		}catch (Exception e){
			System.err.println("JCL facade problem in execute(String className, String methodName, Object... args)");
			
			return null;
		}		
	}

	@Override
	public JCL_result getResultBlocking(String ID) {
		try{
			if(serviceLocation.containsKey(ID)){
				String[] hostPort= serviceLocation.get(ID);
				JCL_message_commons mc = new MessageCommonsImpl();				
				mc.setRegisterData(ID);
				//calling get result from a host in JCL
				mc.setType(6);
				
				JCL_connector taskConnector = new ConnectorImpl();
				taskConnector.connect(hostPort[0], Integer.parseInt(hostPort[1]));
				JCL_message_result msgResult = taskConnector.sendReceive(mc);	
				taskConnector.disconnect();
				
				return msgResult.getResult();
			
			}else return new JCL_resultImpl();
		}catch (Exception e){
			System.err.println("problem in JCL facade getResultBlocking(String ID)");
			JCL_result jclr = new JCL_resultImpl();
			jclr.setErrorResult(e);
			
			return jclr;
		}
	}

	@Override
	public JCL_result getResultUnblocking(String ID) {
		try{
			if(serviceLocation.containsKey(ID)){
				String[] hostPort= serviceLocation.get(ID);
				JCL_message_commons mc = new MessageCommonsImpl();				
				mc.setRegisterData(ID);
				//calling get result unblocking from a host in JCL
				mc.setType(7);
				
				JCL_connector taskConnector = new ConnectorImpl();
				taskConnector.connect(hostPort[0], Integer.parseInt(hostPort[1]));
				JCL_message_result msgResult = taskConnector.sendReceive(mc);	
				taskConnector.disconnect();
				
				return msgResult.getResult();
			
			}else return new JCL_resultImpl();
		}catch (Exception e){
			System.err.println("problem in JCL facade getResultBlocking(String ID)");
			JCL_result jclr = new JCL_resultImpl();
			jclr.setErrorResult(e);
			
			return jclr;
		}
	}

	@Override
	public JCL_result removeResult(String ID) {
		try{
			if(serviceLocation.containsKey(ID)){
				String[] hostPort= serviceLocation.get(ID);
				JCL_message_commons mc = new MessageCommonsImpl();				
				mc.setRegisterData(ID);
				//calling remove result from a host in JCL
				mc.setType(8);
				
				JCL_connector taskConnector = new ConnectorImpl();
				taskConnector.connect(hostPort[0], Integer.parseInt(hostPort[1]));
				JCL_message_result msgResult = taskConnector.sendReceive(mc);	
				
				serviceLocation.remove(ID);
				taskConnector.disconnect();
				
				return msgResult.getResult();
			}else return new JCL_resultImpl();
		}catch (Exception e){
			System.err.println("problem in JCL facade getResultBlocking(String ID)");
			JCL_result jclr = new JCL_resultImpl();
			jclr.setErrorResult(e);
			
			return jclr;
		}
	}

	@Override
	public Object instantiateGlobalVar(String nickName, String varName, File[] jars,
			Object[] defaultVarValue) {
		try{
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(nickName);
			//requiring a host to instantiate a global var remotely 
			mc.setType(9);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length==2){
				String host = mr.getRegisterData()[0];
				String port = mr.getRegisterData()[1];				
				
				JCL_message_global_var gvMessage = new MessageGlobalVarImpl(nickName, varName, jars, defaultVarValue);
				gvMessage.setType(9);
				JCL_connector globalVarConnector = new ConnectorImpl();
				globalVarConnector.connect(host, Integer.parseInt(port));
				JCL_result result = globalVarConnector.sendReceive(gvMessage).getResult();
				globalVarConnector.disconnect();
				
				return result.getCorrectResult();
				
			}else return null;
			
		}catch (Exception e){
			System.err.println("problem in JCL facade instantiateGlobalVar(String nickName, String varName, File[] jars, Object[] defaultVarValue)");
			return null;
		}
	}

	@Override
	public boolean instantiateGlobalVar(String varName, Object instance) {
		try{
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(varName);
			//requiring a host to instantiate a global var remotely 
			mc.setType(10);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length==2){
		
				String host = mr.getRegisterData()[0];
				String port = mr.getRegisterData()[1];
				
				JCL_message_global_var gvMessage = new MessageGlobalVarImpl(varName, instance);
				gvMessage.setType(10);
				JCL_connector globalVarConnector = new ConnectorImpl();
				
				globalVarConnector.connect(host, Integer.parseInt(port));
				
				JCL_result result = globalVarConnector.sendReceive(gvMessage).getResult();
				
				Boolean b = (Boolean) result.getCorrectResult();
				
				globalVarConnector.disconnect();
				
				return b.booleanValue();
			}return false;	
			
		}catch (Exception e){
			System.err.println("problem in JCL facade instantiateGlobalVar(String varName, Object instance)");
			return false;
		}
	}

	@Override
	public boolean destroyGlobalVar(String varName) {
		try{
			
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(varName);
			//requiring a host to instantiate a global var remotely 
			mc.setType(11);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length==2){
				
				String host = mr.getRegisterData()[0];
				String port = mr.getRegisterData()[1];
				
				JCL_message_commons gvMessage = new MessageCommonsImpl();
				gvMessage.setRegisterData(varName);
				gvMessage.setType(11);
				JCL_connector globalVarConnector = new ConnectorImpl();
				globalVarConnector.connect(host, Integer.parseInt(port));
				JCL_result result = globalVarConnector.sendReceive(gvMessage).getResult();
				
				Boolean b = (Boolean) result.getCorrectResult();
				
				globalVarConnector.disconnect();
				
				return b.booleanValue();
			}else return false;
			
		}catch (Exception e){
			System.err.println("problem in JCL facade destroyGlobalVar");
			return false;
		}
	}

	@Override
	public boolean setValue(String varName, Object value) {
		try{
			
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(varName);
			mc.setType(12);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length==2){
				
				String host = mr.getRegisterData()[0];
				String port = mr.getRegisterData()[1];
				
				JCL_message_global_var gvMessage = new MessageGlobalVarImpl(varName, value);
				gvMessage.setType(12);
				JCL_connector globalVarConnector = new ConnectorImpl();
				globalVarConnector.connect(host, Integer.parseInt(port));
				JCL_result result = globalVarConnector.sendReceive(gvMessage).getResult();
				
				Boolean b = (Boolean) result.getCorrectResult();
				
				globalVarConnector.disconnect();
				
				return b.booleanValue();
			}else return false;
			
		}catch (Exception e){
			System.err.println("problem in JCL facade setValue");
			return false;
		}
	}

	@Override
	public boolean setValueUnlocking(String varName, Object value) {
		try{
			
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(varName);
			//requiring a host to instantiate a global var remotely 
			mc.setType(13);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length==2){
				
				String host = mr.getRegisterData()[0];
				String port = mr.getRegisterData()[1];
				
				JCL_message_global_var gvMessage = new MessageGlobalVarImpl(varName, value);
				gvMessage.setType(13);
				JCL_connector globalVarConnector = new ConnectorImpl();
				globalVarConnector.connect(host, Integer.parseInt(port));
				JCL_result result = globalVarConnector.sendReceive(gvMessage).getResult();
				
				Boolean b = (Boolean) result.getCorrectResult();
				
				globalVarConnector.disconnect();
				
				return b.booleanValue();
			}else return false;
			
		}catch (Exception e){
			System.err.println("problem in JCL facade setValueUnlocking");
			return false;
		}
	}

	@Override
	public JCL_result getValue(String varName) {
		try{
			
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(varName);
			//requiring a host to instantiate a global var remotely 
			mc.setType(14);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length==2){
				
				String host = mr.getRegisterData()[0];
				String port = mr.getRegisterData()[1];
				
				JCL_message_commons gvMessage = new MessageCommonsImpl();
				gvMessage.setType(14);
				gvMessage.setRegisterData(varName);
				
				JCL_connector globalVarConnector = new ConnectorImpl();
				globalVarConnector.connect(host, Integer.parseInt(port));
				JCL_result result = globalVarConnector.sendReceive(gvMessage).getResult();
				
				
				globalVarConnector.disconnect();
				
				return result;
			}else return new JCL_resultImpl();
			
		}catch (Exception e){
			System.err.println("problem in JCL facade getValue");
			JCL_result jclr = new JCL_resultImpl();
			jclr.setErrorResult(e);
			
			return jclr;
		}
	}

	@Override
	public JCL_result getValueLocking(String varName) {
		try{
			
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(varName);
			//requiring a host to instantiate a global var remotely 
			mc.setType(15);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length==2){
				
				String host = mr.getRegisterData()[0];
				String port = mr.getRegisterData()[1];
				String[] hostPort = {host, port};
				
				JCL_message_commons gvMessage = new MessageCommonsImpl();
				gvMessage.setType(15);
				gvMessage.setRegisterData(varName);
				
				JCL_connector globalVarConnector = new ConnectorImpl();
				globalVarConnector.connect(hostPort[0], Integer.parseInt(hostPort[1]));
				JCL_result result = globalVarConnector.sendReceive(gvMessage).getResult();
				
				
				globalVarConnector.disconnect();
				
				return result;
			}else return new JCL_resultImpl();
			
		}catch (Exception e){
			System.err.println("problem in JCL facade getValueLocking");
			JCL_result jclr = new JCL_resultImpl();
			jclr.setErrorResult(e);
			
			return jclr;
		}
	}

	@Override
	public void destroy() {
		try{
			
			JCL_message_control mc = new MessageControlImpl();
			mc.setType(16);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
			if(mr.getRegisterData().length>=2){				
				for(int i=0; i<mr.getRegisterData().length; i+=2){
					String host = mr.getRegisterData()[i];
					String port = mr.getRegisterData()[i+1];
					JCL_connector taskConnector = new ConnectorImpl();
					taskConnector.connect(host, Integer.parseInt(port));
					JCL_message_commons msg = new MessageCommonsImpl();
					msg.setType(16);
					JCL_result jclR = taskConnector.sendReceive(msg).getResult();	
					System.err.println("destroying ... " + host + " " + jclR.getCorrectResult().toString());
					taskConnector.disconnect();
				}				
			}
						
			
			this.serviceLocation.clear();
			this.serviceLocation=null;
			this.jars.clear();
			this.jars=null;
		
		}catch(Exception e){
			System.err.println("problem in JCL facade destroy");			
		}
			
	}
	
	@Override
	public boolean containsTask(String nickName) {
		
		return jars.containsKey(nickName);
	}

	@Override
	public boolean containsGlobalVar(String nickName) {
		try{
			
			JCL_message_control mc = new MessageControlImpl();
			
			mc.setRegisterData(nickName);
			//requiring a host to instantiate a global var remotely 
			mc.setType(17);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort);
			JCL_message_control mr = controlConnector.sendReceive(mc);
			controlConnector.disconnect();
		
			return new Boolean(mr.getRegisterData()[0]).booleanValue();
		
		}catch (Exception e){
			System.err.println("problem in JCL facade containsGlobalVar(String nickName)");			
			
			return false;
		}
	}
		
	public static JCL_facade getInstance(){
		return Holder.instance;
	}
	
	private static class Holder{
		private static final JCL_facade instance = new JCL_FacadeImpl();
	}		
		
}
